package cn.org.rookie.jeesdp.core.utils;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author LHT
 * &#064;date  2022-10-01 7:05
 */

public abstract class ClassUtils extends org.springframework.util.ClassUtils {
    public static final String DEFAULT_RESOURCE_SUFFIX = "/*.class";
    private static final PathMatchingResourcePatternResolver PATTERN_RESOLVER = new PathMatchingResourcePatternResolver();

    public static List<Class<?>> findClasses(String locationPattern) {

        List<Class<?>> classes = new ArrayList<>();

        try {
            Resource[] resources = PATTERN_RESOLVER.getResources(convertClassNameToResourcePath(locationPattern) + DEFAULT_RESOURCE_SUFFIX);
            for (Resource resource : resources) {
                System.out.println(resource.getURI().getPath());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return classes;
    }

}
